package com.wondersgroup.framework.sample.component.grid.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class GridVOUtil {
	public static String createResult(boolean success, Object[][] gridIds) {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("success", Boolean.valueOf(success));

		if ((success) && (gridIds != null)) {
			JSONArray result = new JSONArray();
			JSONObject ids = new JSONObject();
			Object[][] arr$ = gridIds;
			int len$ = arr$.length;
			for (int i$ = 0; i$ < len$; ++i$) {
				Object[] gridId = arr$[i$];
				JSONArray idArray = new JSONArray();
				List map = new ArrayList();
				for (Iterator j$ = ((List) gridId[1]).iterator(); j$.hasNext();) {
					String id = (String) j$.next();
					JSONObject idObj = new JSONObject();
					idObj.put("id", id);
					idArray.add(idObj);
				}
				ids.put(gridId[0], idArray);
			}
			result.add(ids);
			jsonObject.put("result", result);
		}

		return jsonObject.toString();
	}

	public static String createResult(boolean success) {
		return createResult(success, (Object[][]) null);
	}
}